package com.kidback.bbloc259.api;

import com.google.gson.GsonBuilder;
import com.kidback.bbloc259.api.service.BBService;
import com.kidback.bbloc259.network.base.INetWorkConfig;
import com.kidback.bbloc259.network.base.NetWorkApi;
import com.kidback.bbloc259.network.interceptor.HttpRequestInterceptor;

import okhttp3.Interceptor;
import retrofit2.Converter;
import retrofit2.converter.gson.GsonConverterFactory;

public class BBNetApi extends NetWorkApi {

    private static BBNetApi instance = new BBNetApi();

    public static BBNetApi getInstance() {
        return instance;
    }

    private BBNetApi() {
        initInner(new BBNetConfig());
    }

    public INetWorkConfig iNetWorkRequiredInfo() {
        return iNetWorkRequiredInfo;
    }

    @Override
    protected String getBaseUrl() {
        if (iNetWorkRequiredInfo.host() == INetWorkConfig.Host.Debug) {
            return "http://192.168.0.108:8080/api/v1/";
        } else {
            return "https://www.kidback.top/BBLocServer/bb_loc/api/v1/";
        }
    }

    @Override
    protected Converter.Factory getConverterFactory() {
        return GsonConverterFactory.create(new GsonBuilder().create());
    }

    @Override
    protected Interceptor getInterceptor() {
        return new HttpRequestInterceptor(iNetWorkRequiredInfo);
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public static BBService getBBService() {
        return getInstance().getService(BBService.class);
    }

}
